import axios from 'axios'
import url from '../../util/url'
const user = {
	namespaced: true,
	state: {
		list: [],
		user:[],
		total:0,
		currentPage:1,
		pageSize:3
	},
	mutations: {

	},
	actions: {
		changePage({state,dispatch},page){
			state.currentPage = page
			dispatch('getUser')
		},
		getList({ state }) {
			axios({
				method:'get',
				url:url+'api.php/records/users',
				params:{order:'id,desc',filter:'status,eq,0'}
			}).then(res=>{
				state.list = res.data.records
			}).catch()
		},
		getUser({state}){
			axios({
				method:'get',
				url:url+'api.php/records/users',
				params:{order:'id,desc',page:state.currentPage+','+state.pageSize,filter: 'status,eq,1'}
			}).then(res=>{
				state.user = res.data.records
				state.total = res.data.results
			}).catch()
		},
		pase({dispatch},user){
			axios({
				method:'put',
				data:user,
				url:url+'api.php/records/users/'+user.id
			}).then(()=>{
				dispatch('getList')
				dispatch('getUser')
			}).catch()
		},
		del({dispatch},id){
			axios({
				method:'delete',
				url:url+'api.php/records/users/'+id
			}).then(()=>{
				dispatch('getList')
				dispatch('getUser')
			}).catch()
		}
	}
}
export default user